package com.baijia.tianxiao.connect.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.WebSocketSession;

import com.baijia.tianxiao.connect.enums.CloseReasonEnum;
import com.baijia.tianxiao.connect.service.CheckSessionStatusService;
import com.baijia.tianxiao.connect.util.TianxiaoConnectUtil;


@Service("checkSessionStatusService")
public class TianxiaoCheckSessionStatusServiceImpl implements CheckSessionStatusService{

	@Resource
	TianxiaoConnectUtil tianxiaoConnectUtil;
	
	@Deprecated
	@Async
	@Override
	public void checkInvalidKeys(List<String> sessionKeys) {
		
		
		for(String key:sessionKeys){
			if(TianxiaoConnectUtil.containSession(key)){
				continue;
			}
			//tianxiaoConnectUtil.removeSession(key);
			//逻辑变动，这快功能的处理暂且预留
		}
		
	}

	@Override
	public void removeCloseSession(String sessionKey, String sessionId, String message) {
		WebSocketSession session = TianxiaoConnectUtil.getSession(sessionKey);
		if(session != null && StringUtils.equals(sessionId,session.getId())){
			TianxiaoConnectUtil.closeSessionByReason(session,CloseReasonEnum.RECONNECT_OTHER,message);
		}
		
	}

}          
